Stop capturing output of all dependencies
authorAlex Crichton <alex@alexcrichton.com>
Sun, 21 Sep 2014 17:22:46 +0000 (10:22 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 21 Sep 2014 21:06:58 +0000 (14:06 -0700)
There are some competing concerns when it comes to the output of compiling
dependencies:

* Not capturing anything leads to getting drowned in unrelated output
* Capturing requires coloration be compromised because of the way windows
  terminal colors are implemented.
* Path dependencies are often developed in tandem with the rest of a package,
  and capturing their output is not always desired.

To address these concerns, cargo previously captured output of dependent
compilations and then re-printed it to the screen if an error occurred. This
patch modifies the behavior to as follows:

* No output is captured. This preserves any coloration rustc provides.
* All dependencies are compiled with `-Awarnings`. This should suppress any
  extraneous output from the compiler and it is considered a bug otherwise if
  the compiler prints a warnings when `-Awarnings` is specified.
* All *path* dependencies (`path="..."`, overrides, etc) are *not* compiled with
  `-Awarnings`. The reason for this is that you are always in control of these
  packages and probably want to see warnings anyway.

Closes #490
Closes #496

.travis.install.deps.sh
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_git_deps.rs

index 94d3db28c4c14b0281b6d12a7b6b69aa305f0774..4a082e923b543aeaa7bba151975ec204c70b9658 100755 (executable)
@@ -25,6 +25,7 @@ host=static-rust-lang-org.s3.amazonaws.com
 # just install the right ones? This should enable cross compilation in the
 # future anyway.
 if [ -z "${windows}" ]; then
+    rm -rf rustc *.tar.gz
     curl -O https://$host/dist/rust-nightly-i686-$target.tar.gz
     curl -O https://$host/dist/rust-nightly-x86_64-$target.tar.gz
     tar xfz rust-nightly-i686-$target.tar.gz
@@ -49,6 +50,7 @@ if [ -z "${windows}" ]; then
     rm -f rust-nightly-i686-$target.tar.gz
     rm -f rust-nightly-x86_64-$target.tar.gz
 else
+    rm -rf rustc *.exe
     if [ "${BITS}" = "64" ]; then
         triple=x86_64-w64-mingw32
     else
index f79329639d11884cbb994c987321fb9b5ba83ba3..ea59bab113efaba21a9fd5d4dfa9fd8333bcaf22 100644 (file)
@@ -237,26 +237,19 @@ fn rustc(package: &Package, target: &Target,
     log!(5, "root={}; target={}; crate_types={}; verbose={}; req={}",
          root.display(), target, crate_types, cx.primary, req);
 
-    let primary = cx.primary;
     let rustcs = try!(prepare_rustc(package, target, crate_types, cx, req));
 
     Ok(rustcs.into_iter().map(|(rustc, kind)| {
         let name = package.get_name().to_string();
         let desc = rustc.to_string();
+        let is_path_source = package.get_package_id().get_source_id().is_path();
+        let show_warnings = cx.primary || is_path_source;
+        let rustc = if show_warnings {rustc} else {rustc.arg("-Awarnings")};
 
         (proc() {
-            if primary {
-                log!(5, "executing primary");
-                try!(rustc.exec().chain_error(|| {
-                    human(format!("Could not compile `{}`.", name))
-                }))
-            } else {
-                log!(5, "executing deps");
-                try!(rustc.exec_with_output().and(Ok(())).map_err(|err| {
-                    caused_human(format!("Could not compile `{}`.\n{}",
-                                         name, err.output().unwrap()), err)
-                }))
-            }
+            try!(rustc.exec().chain_error(|| {
+                human(format!("Could not compile `{}`.", name))
+            }));
             Ok(())
         }, kind, desc)
     }).collect())
index dc4c399832f79a449ba3852f02644ab1d4714842..3d3c569d492b8d8c177209aaeb0c6e68646ebb0a 100644 (file)
@@ -213,7 +213,11 @@ test!(cargo_compile_with_warnings_in_a_dep_package {
                               {} foo v0.5.0 ({})\n",
                              COMPILING, p.url(),
                              COMPILING, p.url()))
-        .with_stderr(""));
+        .with_stderr("\
+[..]warning: code is never used: `dead`[..]
+[..]fn dead() {}
+
+"));
 
     assert_that(&p.bin("foo"), existing_file());
 
index 181de8f9b698f804a793caa953e9f7d1f308caad..284ad2622f4380e60012ca237c297322954cd16a 100644 (file)
@@ -1273,3 +1273,36 @@ test!(fetch_downloads {
     assert_that(p.process(cargo_dir().join("cargo")).arg("fetch"),
                 execs().with_status(0).with_stdout(""));
 })
+
+test!(warnings_in_git_dep {
+    let bar = git_repo("bar", |project| {
+        project.file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+        "#)
+        .file("src/lib.rs", "fn unused() {}")
+    }).assert();
+
+    let p = project("foo")
+        .file("Cargo.toml", format!(r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+            [dependencies.bar]
+            git = '{}'
+        "#, bar.url()).as_slice())
+        .file("src/main.rs", "fn main() {}");
+
+    assert_that(p.cargo_process("build"),
+        execs()
+        .with_stdout(format!("{} git repository `{}`\n\
+                              {} bar v0.5.0 ({}#[..])\n\
+                              {} foo v0.5.0 ({})\n",
+                             UPDATING, bar.url(),
+                             COMPILING, bar.url(),
+                             COMPILING, p.url()))
+        .with_stderr(""));
+})